package ${packageName}.${moduleName}.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.fastrise.frjee.core.model.Page;
import com.fastrise.frjee.core.utils.StringUtils;
import com.fastrise.frjee.core.utils.json.RenderUtils;
import com.fastrise.frjee.core.web.BaseController;
import ${packageName}.${moduleName}.model.${ClassName};
import ${packageName}.${moduleName}.service.${ClassName}Service;
import ${packageName}.${moduleName}.web.rto.${ClassName}RTO;
<#if formHead.hisSign == 'true'>
import com.fastrise.frjee.modules.sys.security.SysSecurityHolder;
</#if>

/**   
 * ${functionName}Controller
 * @author ${classAuthor}
 * @version ${classVersion}
 *
 */
@Controller
@RequestMapping(value="/${moduleName}/${className}",produces = "text/html;charset=UTF-8")
public class ${ClassName}Controller extends BaseController{
	
	@Autowired
	private ${ClassName}Service ${className}Service;
	
	@RequestMapping(value = "/index", method = RequestMethod.GET)
	public String index(HttpServletRequest request,ModelMap modelMap) {
		return modulesView("${moduleName}/${className}/${className}Index");
	}
	
	@RequestMapping("/findPage")
	@ResponseBody
	public void findPage(HttpServletResponse response,${ClassName}RTO ${className}RTO){
		Page<${ClassName}> page = ${className}Service.findPage(${className}RTO);
		RenderUtils.renderJqueryEasyUIGrid(response, page);
	}
	
	@RequestMapping("/save")
	@ResponseBody
	public void save(HttpServletResponse response,${ClassName} ${className}){
		if (StringUtils.isNotBlank(${className}.getId())) {
		<#if formHead.hisSign == 'true'>
			${className}.setUpdateId(SysSecurityHolder.getUserId());
		</#if>
			${className}Service.update(${className});
		}else {
		<#if formHead.hisSign == 'true'>
			${className}.setCreateId(SysSecurityHolder.getUserId());
		</#if>
			${className}Service.save(${className});
		}
		RenderUtils.renderJsonResultMsgSuccess(response,"保存成功！");
	}
	
	@RequestMapping("/get")
	public String get(String id, Model model){
		${ClassName} ${className};
		if(StringUtils.isNotBlank(id)){
			${className} = ${className}Service.get(id);
		}else{
			${className} = new ${ClassName}();
		}
		model.addAttribute("${className}", ${className});
		return modulesView("${moduleName}/${className}/${className}Form");
	}
	
	@RequestMapping("/delete")
	@ResponseBody
	public void delete(@RequestParam(value="ids[]", required=true) String ids[],HttpServletResponse response){
		<#if formHead.hisSign == 'true'>
		${className}Service.deleteByIds(ids, SysSecurityHolder.getUserId());
		<#else>
		${className}Service.deleteByIds(ids);
		</#if>
		RenderUtils.renderJsonResultMsgSuccess(response,"删除成功！");
	}
	
}
